import numpy as np
import cv2
import os
import sys
sys.path.append(os.getcwd())
from config.env import Env
env = Env()

cap = cv2.VideoCapture(0)
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter(env.getOutputPath() + "output5.avi", fourcc, 30.0, (640, 480))

if not cap.isOpened():
    print("没有打开摄像头")
    exit()
while True:
    ret, frame = cap.read()
    if not ret:
        print("没有接收到视频帧...")
        break
    
    # 翻转头像
    frame = cv2.flip(frame, 1)
    out.write(frame)
    cv2.imshow("video", frame)
    if cv2.waitKey(1) == ord("q"):
        break

out.release()
cap.release()
cv2.destroyAllWindows()
    